package core.cards.election.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class VotingCard implements Serializable {
	private static final long serialVersionUID = -2826632957679013457L;

	private ElectionBackend electionFormBackend;

	private String name;
	private String description;

	private int checksAllowed;
	private int checksChecked;

	private List<VotingCardOption> votingCardOptionList;

	public VotingCard(ElectionBackend electionFormBackend) {
		this.electionFormBackend = electionFormBackend;
		this.checksChecked = 0;

		votingCardOptionList = new ArrayList<VotingCardOption>();
	}

	public VotingCard(String name, String description, int checksAllowed, ElectionBackend electionFormBackend) {
		setName(name);
		setDescription(description);
		setChecksAllowed(checksAllowed);

		this.electionFormBackend = electionFormBackend;
		this.checksChecked = 0;

		votingCardOptionList = new ArrayList<VotingCardOption>();
	}

	public void addVotingCardOption(VotingCardOption votingSubcard) {
		votingCardOptionList.add(votingSubcard);
	}

	public void removeVotingCardOption(VotingCardOption votingSubcard) {
		votingCardOptionList.remove(votingSubcard);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getChecksAllowed() {
		return checksAllowed;
	}

	public void setChecksAllowed(int checksAllowed) {
		this.checksAllowed = checksAllowed;
	}

	public int getChecksChecked() {
		return checksChecked;
	}

	public void incChecked() {
		checksChecked++;
	}

	public void decChecked() {
		checksChecked--;
	}

	public boolean isValid() {
		return checksChecked <= checksAllowed;
	}

	public String toString() {
		String output = "";
		output += name + "\n";
		output += "\t" + description + "\n";
		for (VotingCardOption votingCardOption : votingCardOptionList) {
			output += "\t\t" + votingCardOption + "\n";
		}

		return output;
	}

	public List<VotingCardOption> getVotingCardOptionList() {
		return votingCardOptionList;
	}

	/**
	 * @return the electionFormBackend
	 */
	public ElectionBackend getElectionFormBackend() {
		return electionFormBackend;
	}
}
